<?php

class modelOptions extends CWidget {

	public function timeInterval() {
		if (date("H", time()) >= 7 || date("H", time()) <= 21)
			return true;
		else
			return false;
	}

	public function getRegions() {
		$regions = Yii::app()->params['regions'];
		$regionId = Yii::app()->session['userRegion']['id'];

		$array[] = array('title' => $regions[$regionId]['regionTitle'], 'phone' => strip_tags($regions[$regionId]['tel']));
		;

		if ($regionId == 1) {
			$array[] = array('title' => $regions[2]['regionTitle'], 'phone' => strip_tags($regions[2]['tel']));
			;
		} else if ($regionId == 2) {
			$array[] = array('title' => $regions[1]['regionTitle'], 'phone' => strip_tags($regions[1]['tel']));
			;
		} else {
			$array[] = array('title' => $regions[1]['regionTitle'], 'phone' => strip_tags($regions[1]['tel']));
			;
			$array[] = array('title' => $regions[2]['regionTitle'], 'phone' => strip_tags($regions[2]['tel']));
			;
		}

		return $array;
	}

	public function run() {
		if ($this->timeInterval()) {
			$this->render('modelOptionsCitys', array('regions' => $this->getRegions()));
		} else
			$this->render('modelOptionsWidget');
	}

}
